﻿using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;

namespace LightSwitchApplication
{
    public partial class CreateNewSalesOrder
    {
        partial void CreateNewSalesOrder_InitializeDataWorkspace(List<IDataService> saveChangesTo)
        {
            var item = this.DataWorkspace.SalesDepData.aspnet_Profiles.Where(c => c.aspnet_User.UserName == this.Application.User.Name).FirstOrDefault();
            if (item != null)
                this.aspnet_Profile_UserId = item.aspnet_User.UserId;
            this.SalesOrderProperty = new SalesOrder();
        }

        partial void CreateNewSalesOrder_Saved()
        {
            this.Close(false);
            Application.Current.ShowDefaultScreen(this.SalesOrderProperty);
        }

        partial void Proceed_Execute()
        {
            this.Save();
        }

        partial void Proceed_CanExecute(ref bool result)
        {
            result = (this.SalesOrderProperty.OrderShop != null);
        }

        partial void Cancel_Execute()
        {
            this.Close(false);
        }
    }
}